package com.example.controller.admin;

import com.example.common.Result;
import com.example.entity.Admin;
import com.example.entity.DTO.AdminDetailDTO;
import com.example.service.admin.AdminService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin")
public class AdminController {

    @Resource
    private AdminService adminService;

    /**
     * 获取全部管理员详细信息
     */

    @GetMapping("/selectAll")
    public Result selectAll() {
        List<AdminDetailDTO> list = adminService.selectAll();
        return Result.success(list);
    }

    /**
     * 添加管理员
     */

    @PostMapping("/add")
    public Result add(@RequestBody Admin admin) {
        adminService.add(admin);
        return Result.success();
    }

    /**
     * 删除管理员
     */
    @DeleteMapping("/deleteById/{id}")
    public Result deleteById(@PathVariable Integer id) {
        adminService.deleteById(id);
        return Result.success();
    }

    /**
     * 更新管理员信息
     */
    @PutMapping("/update")
    public Result update(@RequestBody Admin admin) {
        adminService.update(admin);
        return Result.success();
    }
}
